#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int jisu(n)
{
	int x = 0;
	while (n)
	{
		x += n % 10;
		n /= 10;
	}
	if (x > 9)
	{
		x = jisu(x);
	}
	return x;
}
int main()
{
	int n = 0;
	scanf("%d", &n);
	int m = jisu(n);
	printf("%d", m);
	return 0;
}